<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Put mapping API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'indices-put-mapping.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-put-mapping.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-put-mapping.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/indices-put-mapping.html" rel="nofollow" target="_blank">../en/indices-put-mapping.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="indices.html">Index APIs</a></span>
»
<span class="breadcrumb-node">Put mapping API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="indices-templates.html">« Put index template API</a>
</span>
<span class="next">
<a href="indices-refresh.html">Refresh API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indices-put-mapping"></a>Put mapping API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Adds new fields to an existing index or changes the search settings of existing
fields.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_mapping
{
  "properties": {
    "email": {
      "type": "keyword"
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1692.console"></div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Before 7.0.0, the <em>mappings</em> definition used to include a type name.
Although specifying types in requests is now deprecated, a type can still be
provided if the request parameter <code class="literal">include_type_name</code> is set. For more details,
please see <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a>.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="put-mapping-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">PUT /&lt;index&gt;/_mapping</code></p>
<p><code class="literal">PUT /_mapping</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="put-mapping-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
<p>
(Optional, string) Comma-separated list or wildcard expression of index names
used to limit the request.
</p>
<p>To update the mapping of all indices, omit this parameter or use a value of
<code class="literal">_all</code>.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="put-mapping-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">allow_no_indices</code>
</span>
</dt>
<dd>
<p>
(Optional, boolean) If <code class="literal">true</code>,
the request does <span class="strong strong"><strong>not</strong></span> return an error
if a wildcard expression
or <code class="literal">_all</code> value retrieves only missing or closed indices.
</p>
<p>This parameter also applies to <a class="xref" href="indices-aliases.html" title="Update index alias API">index aliases</a>
that point to a missing or closed index.</p>
<p>Defaults to <code class="literal">false</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">expand_wildcards</code>
</span>
</dt>
<dd>
<p>(Optional, string) Controls what kind of indices that wildcard expressions can
expand to. Multiple values are accepted when separated by a comma, as in
<code class="literal">open,hidden</code>. Valid values are:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">all</code>
</span>
</dt>
<dd>
Expand to open and closed indices, including <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
</dd>
<dt>
<span class="term">
<code class="literal">open</code>
</span>
</dt>
<dd>
Expand only to open indices.
</dd>
<dt>
<span class="term">
<code class="literal">closed</code>
</span>
</dt>
<dd>
Expand only to closed indices.
</dd>
<dt>
<span class="term">
<code class="literal">hidden</code>
</span>
</dt>
<dd>
Expansion of wildcards will include <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
Must be combined with <code class="literal">open</code>, <code class="literal">closed</code>, or both.
</dd>
<dt>
<span class="term">
<code class="literal">none</code>
</span>
</dt>
<dd>
Wildcard expressions are not accepted.
</dd>
</dl>
</div>
<p>Defaults to <code class="literal">open</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">include_type_name</code>
</span>
</dt>
<dd>
<span class="Admonishment Admonishment--change">
[<span class="Admonishment-version u-mono u-strikethrough">7.0.0</span>]
<span class="Admonishment-detail">
Deprecated in 7.0.0. Mapping types have been deprecated. See <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a>.
</span>
</span>
(Optional, boolean) If <code class="literal">true</code>, a mapping type is expected in the body of
mappings. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ignore_unavailable</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, missing or closed indices are not included in the
response. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="put-mapping-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">properties</code>
</span>
</dt>
<dd>
<p>(Required, <a class="xref" href="mapping.html" title="Mapping">mapping object</a>) Mapping for a field. For new
fields, this mapping can include:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Field name
</li>
<li class="listitem">
<a class="xref" href="mapping.html#field-datatypes" title="Field datatypes">Field datatype</a>
</li>
<li class="listitem">
<a class="xref" href="mapping-params.html" title="Mapping parameters">Mapping parameters</a>
</li>
</ul>
</div>
<p>For existing fields, see <a class="xref" href="indices-put-mapping.html#updating-field-mappings" title="Change the mapping of an existing field">Change the mapping of an existing field</a>.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="put-mapping-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="put-field-mapping-api-basic-ex"></a>Example with index setup<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The put mapping API requires an existing index. The following
<a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API request creates the <code class="literal">publications</code>
index with no mapping.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /publications</pre>
</div>
<div class="console_widget" data-snippet="snippets/1693.console"></div>
<p>The following put mapping API request adds <code class="literal">title</code>, a new <a class="xref" href="text.html" title="Text datatype"><code class="literal">text</code></a> field,
to the <code class="literal">publications</code> index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /publications/_mapping
{
  "properties": {
    "title":  { "type": "text"}
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1694.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="put-mapping-api-multi-ex"></a>Multiple indices<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The PUT mapping API can be applied to multiple indices with a single request.
For example, we can update the <code class="literal">twitter-1</code> and <code class="literal">twitter-2</code> mappings at the same time:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console"># Create the two indices
PUT /twitter-1
PUT /twitter-2

# Update both mappings
PUT /twitter-1,twitter-2/_mapping <a id="CO571-1"></a><i class="conum" data-value="1"></i>
{
  "properties": {
    "user_name": {
      "type": "text"
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1695.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO571-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Note that the indices specified (<code class="literal">twitter-1,twitter-2</code>) follows <a class="xref" href="multi-index.html" title="Multiple indices">multiple index names</a> and wildcard format.</p>
</td>
</tr>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="add-new-field-to-object"></a>Add new properties to an existing object field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use the put mapping API
to add new properties
to an existing <a class="xref" href="object.html" title="Object datatype"><code class="literal">object</code></a> field.
To see how this works,
try the following example.</p>
<p>Use the <a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API
to create an index
with the <code class="literal">name</code> object field
and an inner <code class="literal">first</code> text field.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index
{
  "mappings": {
    "properties": {
      "name": {
        "properties": {
          "first": {
            "type": "text"
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1696.console"></div>
<p>Use the put mapping API
to add a new inner <code class="literal">last</code> text field
to the <code class="literal">name</code> field.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index/_mapping
{
  "properties": {
    "name": {
      "properties": {
        "last": {
          "type": "text"
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1697.console"></div>
<p>Use the <a class="xref" href="indices-get-mapping.html" title="Get mapping API">get mapping</a> API
to verify your changes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /my_index/_mapping</pre>
</div>
<div class="console_widget" data-snippet="snippets/1698.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "my_index" : {
    "mappings" : {
      "properties" : {
        "name" : {
          "properties" : {
            "first" : {
              "type" : "text"
            },
            "last" : {
              "type" : "text"
            }
          }
        }
      }
    }
  }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="add-multi-fields-existing-field-ex"></a>Add multi-fields to an existing field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p><a class="xref" href="multi-fields.html" title="fields">Multi-fields</a>
let you index the same field
in different ways.
You can use the put mapping API
to update the <code class="literal">fields</code> mapping parameter
and enable multi-fields for an existing field.</p>
<p>To see how this works,
try the following example.</p>
<p>Use the <a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API
to create an index
with the <code class="literal">city</code> <a class="xref" href="text.html" title="Text datatype">text</a> field.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index
{
  "mappings": {
    "properties": {
      "city": {
        "type": "text"
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1699.console"></div>
<p>While text fields work well for full-text search,
<a class="xref" href="keyword.html" title="Keyword datatype">keyword</a> fields are not analyzed
and may work better for sorting or aggregations.</p>
<p>Use the put mapping API
to enable a multi-field for the <code class="literal">city</code> field.
This request adds the <code class="literal">city.raw</code> keyword multi-field,
which can be used for sorting.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index/_mapping
{
  "properties": {
    "city": {
      "type": "text",
      "fields": {
        "raw": {
          "type": "keyword"
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1700.console"></div>
<p>Use the <a class="xref" href="indices-get-mapping.html" title="Get mapping API">get mapping</a> API
to verify your changes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /my_index/_mapping</pre>
</div>
<div class="console_widget" data-snippet="snippets/1701.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "my_index" : {
    "mappings" : {
      "properties" : {
        "city" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" : "keyword"
            }
          }
        }
      }
    }
  }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="change-existing-mapping-parms"></a>Change supported mapping parameters for an existing field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The documentation for each <a class="xref" href="mapping-params.html" title="Mapping parameters">mapping parameter</a>
indicates whether you can update it
for an existing field
using the put mapping API.
For example,
you can use the put mapping API
to update the <a class="xref" href="ignore-above.html" title="ignore_above"><code class="literal">ignore_above</code></a> parameter.</p>
<p>To see how this works,
try the following example.</p>
<p>Use the <a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API to create an index
containing a <code class="literal">user_id</code> keyword field.
The <code class="literal">user_id</code> field
has an <code class="literal">ignore_above</code> parameter value
of <code class="literal">20</code>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index
{
  "mappings": {
    "properties": {
      "user_id": {
        "type": "keyword",
        "ignore_above": 20
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1702.console"></div>
<p>Use the put mapping API
to change the <code class="literal">ignore_above</code> parameter value
to <code class="literal">100</code>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index/_mapping
{
  "properties": {
    "user_id": {
      "type": "keyword",
      "ignore_above": 100
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1703.console"></div>
<p>Use the <a class="xref" href="indices-get-mapping.html" title="Get mapping API">get mapping</a> API
to verify your changes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /my_index/_mapping</pre>
</div>
<div class="console_widget" data-snippet="snippets/1704.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "my_index" : {
    "mappings" : {
      "properties" : {
        "user_id" : {
          "type" : "keyword",
          "ignore_above" : 100
        }
      }
    }
  }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="updating-field-mappings"></a>Change the mapping of an existing field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Except for supported <a class="xref" href="mapping-params.html" title="Mapping parameters">mapping parameters</a>,
you can’t change the mapping or field type of an existing field.
Changing an existing field could invalidate data that’s already indexed.</p>
<p>If you need to change the mapping of a field,
create a new index with the correct mapping
and <a class="xref" href="docs-reindex.html" title="Reindex API">reindex</a> your data into that index.</p>
<p>To see how this works,
try the following example.</p>
<p>Use the <a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API
to create the <code class="literal">users</code> index
with the <code class="literal">user_id</code> field
with the <a class="xref" href="number.html" title="Numeric datatypes"><code class="literal">long</code></a> field type.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /users
{
  "mappings" : {
    "properties": {
      "user_id": {
        "type": "long"
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1705.console"></div>
<p>Use the <a class="xref" href="docs-index_.html" title="Index API">index</a> API
to index several documents
with <code class="literal">user_id</code> field values.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /users/_doc?refresh=wait_for
{
    "user_id" : 12345
}

POST /users/_doc?refresh=wait_for
{
    "user_id" : 12346
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1706.console"></div>
<p>To change the <code class="literal">user_id</code> field
to the <a class="xref" href="keyword.html" title="Keyword datatype"><code class="literal">keyword</code></a> field type,
use the create index API
to create the <code class="literal">new_users</code> index with the correct mapping.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /new_users
{
  "mappings" : {
    "properties": {
      "user_id": {
        "type": "keyword"
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1707.console"></div>
<p>Use the <a class="xref" href="docs-reindex.html" title="Reindex API">reindex</a> API
to copy documents from the <code class="literal">users</code> index
to the <code class="literal">new_users</code> index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_reindex
{
  "source": {
    "index": "users"
  },
  "dest": {
    "index": "new_users"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1708.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "took": 147,
  "timed_out": false,
  "total": 2,
  "updated": 0,
  "created": 2,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1.0,
  "throttled_until_millis": 0,
  "failures" : [ ]
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rename-existing-field"></a>Rename a field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/put-mapping.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Renaming a field would invalidate data already indexed under the old field name.
Instead, add an <a class="xref" href="alias.html" title="Alias datatype"><code class="literal">alias</code></a> field to create an alternate field name.</p>
<p>For example,
use the <a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API
to create an index
with the <code class="literal">user_identifier</code> field.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index
{
  "mappings": {
    "properties": {
      "user_identifier": {
        "type": "keyword"
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1709.console"></div>
<p>Use the put mapping API to add the <code class="literal">user_id</code> field alias
for the existing <code class="literal">user_identifier</code> field.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index/_mapping
{
  "properties": {
    "user_id": {
      "type": "alias",
      "path": "user_identifier"
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1710.console"></div>
<p>Use the <a class="xref" href="indices-get-mapping.html" title="Get mapping API">get mapping</a> API
to verify your changes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /my_index/_mapping</pre>
</div>
<div class="console_widget" data-snippet="snippets/1711.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "my_index" : {
    "mappings" : {
      "properties" : {
        "user_id" : {
          "type" : "alias",
          "path" : "user_identifier"
        },
        "user_identifier" : {
          "type" : "keyword"
        }
      }
    }
  }
}</pre>
</div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="indices-templates.html">« Put index template API</a>
</span>
<span class="next">
<a href="indices-refresh.html">Refresh API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>